package com.mine.site.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.mine.site.dao.CommodityDao;
import com.mine.site.model.Commodity;



/**
 * Servlet implementation class XiangxiServlet
 */
@WebServlet("/XiangxiServlet")
public class XiangxiServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private static final String name = null;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public XiangxiServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

		String method = request.getParameter("m");
		if("detail".equals(method)){
			this.detail(request, response);
		}
		else{
			this.list(request, response);
		}
	}

	private void list(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

		String name = request.getParameter("name");
		CommodityDao dao = new CommodityDao();
		List<Commodity> Commo = dao.findByName(name);
		request.setAttribute("CommoList", Commo);
		request.getRequestDispatcher("xiangxi.jsp").forward(request, response);

	}
		

	private void detail(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String number = request.getParameter("number");
		CommodityDao dao = new CommodityDao();
		Commodity Commo = dao.findByNumber(number);
		request.setAttribute("CommoList", Commo);
		request.getRequestDispatcher("xiangxi.jsp").forward(request, response);
		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		this.doGet(request, response);
	}

}
